package com.cgs.springboottes2secrity.sec;

import com.cgs.springboottes2secrity.entity.User;
import com.cgs.springboottes2secrity.repository.UserRepository;
import lombok.Data;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @author cgs
 * @version woNiu 98
 * @date 2023/5/10 17:41
 */

public class SecUserDetailsService implements UserDetailsService {
    @Resource
    private UserRepository ur;
    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        User user = ur.getByAccount(account);
        if(user==null){
            throw new UsernameNotFoundException("没这个用户");
        }
        return new SecUser(user.getId(), account, user.getPwd(), new ArrayList<>());
    }
}
